package com.mlk.engUser.api;

import com.mlk.constant.OK;
import com.mlk.core.util.ServerResponse;
import com.mlk.engUser.po.EngUserAddress;
import com.mlk.engUser.service.EngUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 用户管理部分
 */
@RequestMapping("/api/eng/userAddress")
@Controller
@Api(value = "用户地址管理")
public class EngUserAddressAPI {

    @Resource
    private EngUserService engUserService;

    @PostMapping("addAddress")
    @ResponseBody
    @ApiOperation("添加地址")
    @OK
    public ServerResponse addAddress(EngUserAddress engUserAddress) {
        return this.engUserService.addAddress(engUserAddress);
    }

    @GetMapping("addressList")
    @ResponseBody
    @ApiOperation("用户地址列表")
    @OK
    public ServerResponse addressList(String openId) {
        return this.engUserService.addressList(openId);
    }

    /**
     * 设置为默认地址
     * @return
     */
    @ApiOperation("设置为用户默认地址")
    @ResponseBody
    @PostMapping("updateDefaultAddress")
    @OK
    public ServerResponse updateDefaultAddress(String openId,Integer id){
        return this.engUserService.updateDefaultAddress(openId,id);
    }

    @PostMapping("updateUserAddress")
    @ResponseBody
    @ApiOperation("修改用户地址信息")
    @OK
    public ServerResponse updateUserAddress(EngUserAddress engUserAddress){
        return this.engUserService.updateUserAddress(engUserAddress);
    }

    @GetMapping("deleteAddress")
    @ResponseBody
    @ApiOperation("删除用户地址信息")
    @OK
    public ServerResponse deleteAddress(Integer id){
        return this.engUserService.deleteAddress(id);
    }

    /**
     * 获取默认的地址
     * @return
     */
    @GetMapping("getDefaultAddress")
    @ResponseBody
    public ServerResponse getDefaultAddress(String openId){
        return this.engUserService.getDefaultAddress(openId);
    }


}
